package br.Dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

import br.Bean.AgenciaBean;

public class AgenciaDao {

	public void inserir(Connection conn, AgenciaBean value) throws SQLException {
		String sql = "INSERT INTO agencia(numeroagencia, nome) VALUES (?, ?);";

		PreparedStatement ps = conn.prepareStatement(sql);

		ps.setInt(1, value.getAgencia());
		ps.setString(2, value.getNome());
		ps.execute();
		ps.close();

	}

	public void excluir(Connection conn, AgenciaBean value) throws Exception {

		String sql = "DELETE FROM agencia WHERE id = ?";
		PreparedStatement ps = conn.prepareStatement(sql);
		ps.setInt(1, value.getId());
		ps.execute();
	}

	public void alterar(Connection conn, AgenciaBean value) throws Exception {

		String sql = "UPDATE agencia SET id=?, agencia=?, nome=? WHERE  id = ?";

		PreparedStatement ps = conn.prepareStatement(sql);
		ps.setInt(1, value.getAgencia());
		ps.setString(2, value.getNome());

		ps.execute();
		ps.close();
	}

}
